package org.leetcode.middle.leetcode230;

import org.leetcode.TreeNode;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public int kthSmallest(TreeNode root, int k) {

        ArrayList<Integer> list = new ArrayList<>();

        putTree(root,list);

//        int [] res = new int[list.size()];
//
//        int index=0;
//        for (int num:list) {
//            res[index]=num;
//            index++;
//        }

//        Arrays.sort(res);

      return list.get(k-1);
    }

    private void putTree(TreeNode node, List list){

        if (node==null){
            return;
        }


        putTree(node.left,list);

        list.add(node.val);

        putTree(node.right,list);
    }

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();

        list.add(1);
        list.add(2);
        list.add(3);

        for (int num:list) {
            System.out.println(num);
        }

        int [] res= new int[3];

        res[0]=1;
        res[1]=2;
        res[2]=3;

        Arrays.sort(res);

        System.out.println(res[0]);
        System.out.println(res[2]);

    }
}
